package airacrobats.gui.container;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.TitledBorder;

/**
 * This is the panel that shows the resources being loaded.
 */
public class LoadingResourcesContainer extends JPanel
{
    /**
     * Preferred size of the loading container.
     */
    private final static Dimension PREFERRED_SIZE = new Dimension(500, 50);

    /**
     * Progress bar.
     */
    private JProgressBar progressBar;

    /**
     */
    public LoadingResourcesContainer()
    {
        setLayout(new GridBagLayout());
        setBorder(new TitledBorder("Loading resources"));
        setPreferredSize(PREFERRED_SIZE);

        progressBar = new JProgressBar();
        progressBar.setStringPainted(true);

        GridBagConstraints c = new GridBagConstraints();

        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        add(progressBar, c);
    }

    /**
     * Updates the progress bar.
     * @param increment The amount to increment (between 0-1).
     * @param message The message to show.
     */
    public void updateProgress(double increment, String message)
    {
        progressBar.setValue(progressBar.getValue() + (int) (increment * progressBar.getMaximum()));
        progressBar.setString(message + " " + progressBar.getValue() + "%");
    }

    /**
     * @return True if the value of the progress bar equals its maximum value.
     */
    public boolean isProgressBarFull()
    {
        return progressBar.getPercentComplete() == 1;
    }
}
